//
//  UserInfoCell.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 16/1/20.
//  Copyright © 2016年 GripMeMory. All rights reserved.
//

#import "UserInfoCell.h"
#import "UserInfoModel.h"

#define kTitleLabelLeftMargin 30 / 2
#define kTitleLabelRightMargin 25 / 2
#define kDetailLabelRightMargin 20 / 2
#define kEnterImageViewWidth 20 / 2
#define kSwitchWidth 80 / 2
#define kSwitchTopMargin 15 / 2


@implementation UserInfoCell

{
    UILabel *_titleLabel;
    UILabel *_detailLabel;
    UIImageView *_enterImageView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _titleLabel = [[UILabel alloc] init];
        
        _detailLabel = [[UILabel alloc] init];
        _detailLabel.textAlignment = NSTextAlignmentRight;
        
        _enterImageView = [[UIImageView alloc] init];
        _enterImageView.image = [UIImage imageNamed:@"进入"];
        _enterImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        self.contentView.backgroundColor = [UIColor clearColor];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self addSubview:_titleLabel];
        [self addSubview:_detailLabel];
        [self addSubview:_enterImageView];
    }
    return self;
}

- (void)drawRect:(CGRect)rect{
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    
    //下分割线
    CGContextSetStrokeColorWithColor(context, [RGB_COLOR(@"#c9c9c9") CGColor]);
    CGContextStrokeRect(context, CGRectMake(kTitleLabelLeftMargin, rect.size.height, rect.size.width -  kTitleLabelLeftMargin - kTitleLabelRightMargin, 1));
}

- (void)layoutSubviews{
    _titleLabel.frame = CGRectMake(kTitleLabelLeftMargin, 0, (self.width - kTitleLabelLeftMargin - kTitleLabelRightMargin - kDetailLabelRightMargin - kEnterImageViewWidth) / 2, self.height);
    _detailLabel.frame = CGRectMake(_titleLabel.right, 0, _titleLabel.width, self.height);
    _enterImageView.frame = CGRectMake(_detailLabel.right + kDetailLabelRightMargin, 0, kEnterImageViewWidth, self.height);
}

- (void)configureCellWithModel:(UserInfoModel *)model{
    _titleLabel.text = model.title;
    _detailLabel.text = model.detail;
    if (model.type == NO) {
        [_enterImageView removeFromSuperview];
    }
}

@end
